package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.service.IJingyingtypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Jingyingtype;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 经营类型 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/jingyingtype")
public class JingyingtypeController extends BaseController
{
    private String prefix = "system/jingyingtype";
	
	@Autowired
	private IJingyingtypeService jingyingtypeService;
	
	@RequiresPermissions("system:jingyingtype:view")
	@GetMapping()
	public String jingyingtype()
	{
	    return prefix + "/jingyingtype";
	}
	
	/**
	 * 查询经营类型列表
	 */
	@RequiresPermissions("system:jingyingtype:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Jingyingtype jingyingtype)
	{
		startPage();
        List<Jingyingtype> list = jingyingtypeService.selectJingyingtypeList(jingyingtype);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出经营类型列表
	 */
	@RequiresPermissions("system:jingyingtype:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Jingyingtype jingyingtype)
    {
    	List<Jingyingtype> list = jingyingtypeService.selectJingyingtypeList(jingyingtype);
        ExcelUtil<Jingyingtype> util = new ExcelUtil<Jingyingtype>(Jingyingtype.class);
        return util.exportExcel(list, "jingyingtype");
    }
	
	/**
	 * 新增经营类型
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存经营类型
	 */
	@RequiresPermissions("system:jingyingtype:add")
	@Log(title = "经营类型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Jingyingtype jingyingtype)
	{		
		return toAjax(jingyingtypeService.insertJingyingtype(jingyingtype));
	}

	/**
	 * 修改经营类型
	 */
	@GetMapping("/edit/{jingyingtypeId}")
	public String edit(@PathVariable("jingyingtypeId") Integer jingyingtypeId, ModelMap mmap)
	{
		Jingyingtype jingyingtype = jingyingtypeService.selectJingyingtypeById(jingyingtypeId);
		mmap.put("jingyingtype", jingyingtype);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存经营类型
	 */
	@RequiresPermissions("system:jingyingtype:edit")
	@Log(title = "经营类型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Jingyingtype jingyingtype)
	{		
		return toAjax(jingyingtypeService.updateJingyingtype(jingyingtype));
	}
	
	/**
	 * 删除经营类型
	 */
	@RequiresPermissions("system:jingyingtype:remove")
	@Log(title = "经营类型", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(jingyingtypeService.deleteJingyingtypeByIds(ids));
	}
	
}
